$(function () {
    let layer = layui.layer
    let form = layui.form
    initUserInfo()
    function initUserInfo() {
        axios({
            method: 'GET',
            url: '/my/userinfo',
            headers: {
                Authorization: localStorage.getItem('token')
            }
        }).then((res) => {
            // console.log(res.data );
            let obj = res.data
            if (obj.status !== 0) {
                return layer.msg(obj.message)
            }
            form.val("formUserInfo", obj.data)
        })
    }
    form.verify({
        nickname: function (value) {
            if (value.length > 10) {
                return "昵称1-10之间"
            }
        }
    })

    $('form').on('submit',function (e) {
        e.preventDefault()
        axios({
            method:'POST',
            url:'/my/userinfo',
            data:$('form').serialize(),
            // headers:{
            //     Authorization: localStorage.getItem('token')
            // }
        }).then((res)=>{
            let obj=res.data
            if(obj.status!==0){
                return layer.msg(obj.message)
            }
            layer.msg('修改成功')
            window.parent.getUserInfo()
        })
    })
    $('form').on('reset',function (e) {
        e.preventDefault()
        initUserInfo()
    })
})
